{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "19c615b7",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from pyecharts.charts import Funnel\n",
    "from pyecharts import options as opts \n",
    "from pyecharts.globals import ThemeType\n",
    "from pyecharts.commons.utils import JsCode\n",
    "image_path='logo.png'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7ab71fe8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c507725c",
   "metadata": {},
   "outputs": [],
   "source": [
    "df=pd.read_excel('C:/Users/hcc/Python高级应用/数据表/相关词热度排名前十(1).xlsx')\n",
    "fun=(\n",
    "    Funnel(init_opts=opts.InitOpts(theme=ThemeType.DARK))\n",
    "    .add(\"日均值\",\n",
    "         [list(z) for z in zip(df['相关词'],df['搜索热度'])],\n",
    "         label_opts=opts.LabelOpts(position=\"inside\"),\n",
    "        )\n",
    "    .set_global_opts(graphic_opts=[\n",
    "                         opts.GraphicGroup(\n",
    "                             graphic_item=opts.GraphicItem(\n",
    "                                 rotation=JsCode(\"Math.PI / 4\"),\n",
    "                                 bounding=\"raw\",\n",
    "                                 right=110,\n",
    "                                 bottom=110,\n",
    "                                 z=100\n",
    "                             ),\n",
    "                             children=[\n",
    "                                 opts.GraphicRect(\n",
    "                                     graphic_item=opts.GraphicItem(\n",
    "                                         left=\"center\",\n",
    "                                         top=\"center\", \n",
    "                                         z=100\n",
    "                                     ),\n",
    "                                     graphic_shape_opts=opts.GraphicShapeOpts(width=400, height=50),\n",
    "                                     graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(\n",
    "                                         fill=\"rgba(0,0,0,0.3)\"\n",
    "                                     ),\n",
    "                                 ),\n",
    "                                 opts.GraphicText(\n",
    "                                     graphic_item=opts.GraphicItem(\n",
    "                                         left=\"center\", \n",
    "                                         top=\"center\", \n",
    "                                         z=100\n",
    "                                     ),\n",
    "                                     graphic_textstyle_opts=opts.GraphicTextStyleOpts(\n",
    "                                         text=\"相关词热度排名前十\",\n",
    "                                         font=\"bold 26px Microsoft YaHei\",\n",
    "                                         graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(\n",
    "                                             fill=\"#fff\"\n",
    "                                         ),\n",
    "                                     ),\n",
    "                                 ),\n",
    "                             ],\n",
    "                         )\n",
    "                     ],\n",
    "                    legend_opts=opts.LegendOpts(type_=\"scroll\", pos_bottom=\"8%\",pos_left=\"5%\", orient=\"vertical\")\n",
    "                    )\n",
    ")\n",
    "fun.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "76bd6699",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/v5/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"74a9d45dd1c0496592aca31fab97a89e\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_74a9d45dd1c0496592aca31fab97a89e = echarts.init(\n",
       "                    document.getElementById('74a9d45dd1c0496592aca31fab97a89e'), 'dark', {renderer: 'canvas'});\n",
       "                var option_74a9d45dd1c0496592aca31fab97a89e = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"aria\": {\n",
       "        \"enabled\": false\n",
       "    },\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"funnel\",\n",
       "            \"name\": \"\\u65e5\\u5747\\u503c\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u6821\\u56ed\\u6b3a\\u51cc\",\n",
       "                    \"value\": 1271\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9738\\u51cc\",\n",
       "                    \"value\": 989\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6821\\u56ed\\u9738\\u51cc\\u4e8b\\u4ef6\\u600e\\u4e48\\u5904\\u7406\",\n",
       "                    \"value\": 656\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6821\\u56ed\\u66b4\\u529b\",\n",
       "                    \"value\": 428\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"3\\u4e2a\\u5c0f\\u5b69\\u6740\\u540c\\u5b66\\u6700\\u65b0\\u6d88\\u606f\",\n",
       "                    \"value\": 384\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6559\\u80b2\\u5c40\\u4e3e\\u62a5\\u7535\\u8bdd\",\n",
       "                    \"value\": 328\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6821\\u56ed\\u9738\\u51cc\\u4e8b\\u4ef6\",\n",
       "                    \"value\": 227\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5317\\u90af\\u90f8\\u6821\\u56ed\\u9738\\u51cc\",\n",
       "                    \"value\": 220\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9752\\u5c11\\u5e74\\u72af\\u7f6a\",\n",
       "                    \"value\": 185\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e08\\u5b97\",\n",
       "                    \"value\": 173\n",
       "                }\n",
       "            ],\n",
       "            \"sort\": \"descending\",\n",
       "            \"gap\": 0,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"inside\",\n",
       "                \"margin\": 8\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"3\\u4e2a\\u5c0f\\u5b69\\u6740\\u540c\\u5b66\\u6700\\u65b0\\u6d88\\u606f\",\n",
       "                \"\\u5e08\\u5b97\",\n",
       "                \"\\u6821\\u56ed\\u66b4\\u529b\",\n",
       "                \"\\u6821\\u56ed\\u9738\\u51cc\\u4e8b\\u4ef6\\u600e\\u4e48\\u5904\\u7406\",\n",
       "                \"\\u6cb3\\u5317\\u90af\\u90f8\\u6821\\u56ed\\u9738\\u51cc\",\n",
       "                \"\\u6559\\u80b2\\u5c40\\u4e3e\\u62a5\\u7535\\u8bdd\",\n",
       "                \"\\u9738\\u51cc\",\n",
       "                \"\\u6821\\u56ed\\u6b3a\\u51cc\",\n",
       "                \"\\u6821\\u56ed\\u9738\\u51cc\\u4e8b\\u4ef6\",\n",
       "                \"\\u9752\\u5c11\\u5e74\\u72af\\u7f6a\"\n",
       "            ],\n",
       "            \"selected\": {},\n",
       "            \"type\": \"scroll\",\n",
       "            \"show\": true,\n",
       "            \"left\": \"5%\",\n",
       "            \"bottom\": \"8%\",\n",
       "            \"orient\": \"vertical\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderRadius\": 0,\n",
       "            \"pageButtonItemGap\": 5,\n",
       "            \"pageButtonPosition\": \"end\",\n",
       "            \"pageFormatter\": \"{current}/{total}\",\n",
       "            \"pageIconColor\": \"#2f4554\",\n",
       "            \"pageIconInactiveColor\": \"#aaa\",\n",
       "            \"pageIconSize\": 15,\n",
       "            \"animationDurationUpdate\": 800,\n",
       "            \"selector\": false,\n",
       "            \"selectorPosition\": \"auto\",\n",
       "            \"selectorItemGap\": 7,\n",
       "            \"selectorButtonGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"enterable\": false,\n",
       "        \"confine\": false,\n",
       "        \"appendToBody\": false,\n",
       "        \"transitionDuration\": 0.4,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5,\n",
       "        \"order\": \"seriesAsc\"\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"target\": \"blank\",\n",
       "            \"subtarget\": \"blank\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"textAlign\": \"auto\",\n",
       "            \"textVerticalAlign\": \"auto\",\n",
       "            \"triggerEvent\": false\n",
       "        }\n",
       "    ],\n",
       "    \"graphic\": [\n",
       "        {\n",
       "            \"type\": \"group\",\n",
       "            \"diffChildrenByName\": false,\n",
       "            \"children\": [\n",
       "                {\n",
       "                    \"type\": \"rect\",\n",
       "                    \"$action\": \"merge\",\n",
       "                    \"rotation\": 0,\n",
       "                    \"left\": \"center\",\n",
       "                    \"top\": \"center\",\n",
       "                    \"bounding\": \"all\",\n",
       "                    \"z\": 100,\n",
       "                    \"zlevel\": 0,\n",
       "                    \"silent\": false,\n",
       "                    \"invisible\": false,\n",
       "                    \"ignore\": false,\n",
       "                    \"cursor\": \"pointer\",\n",
       "                    \"draggable\": false,\n",
       "                    \"progressive\": false,\n",
       "                    \"width\": 0,\n",
       "                    \"height\": 0,\n",
       "                    \"shape\": {\n",
       "                        \"x\": 0,\n",
       "                        \"y\": 0,\n",
       "                        \"width\": 400,\n",
       "                        \"height\": 50\n",
       "                    },\n",
       "                    \"style\": {\n",
       "                        \"fill\": \"rgba(0,0,0,0.3)\",\n",
       "                        \"line_width\": 0\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"type\": \"text\",\n",
       "                    \"$action\": \"merge\",\n",
       "                    \"rotation\": 0,\n",
       "                    \"left\": \"center\",\n",
       "                    \"top\": \"center\",\n",
       "                    \"bounding\": \"all\",\n",
       "                    \"z\": 100,\n",
       "                    \"zlevel\": 0,\n",
       "                    \"silent\": false,\n",
       "                    \"invisible\": false,\n",
       "                    \"ignore\": false,\n",
       "                    \"cursor\": \"pointer\",\n",
       "                    \"draggable\": false,\n",
       "                    \"progressive\": false,\n",
       "                    \"width\": 0,\n",
       "                    \"height\": 0,\n",
       "                    \"style\": {\n",
       "                        \"text\": \"\\u76f8\\u5173\\u8bcd\\u70ed\\u5ea6\\u6392\\u540d\\u524d\\u5341\",\n",
       "                        \"x\": 0,\n",
       "                        \"y\": 0,\n",
       "                        \"font\": \"bold 26px Microsoft YaHei\",\n",
       "                        \"textAlign\": \"left\",\n",
       "                        \"fill\": \"#fff\",\n",
       "                        \"line_width\": 0\n",
       "                    }\n",
       "                }\n",
       "            ],\n",
       "            \"$action\": \"merge\",\n",
       "            \"rotation\": Math.PI / 4,\n",
       "            \"right\": 110,\n",
       "            \"bottom\": 110,\n",
       "            \"bounding\": \"raw\",\n",
       "            \"z\": 100,\n",
       "            \"zlevel\": 0,\n",
       "            \"silent\": false,\n",
       "            \"invisible\": false,\n",
       "            \"ignore\": false,\n",
       "            \"cursor\": \"pointer\",\n",
       "            \"draggable\": false,\n",
       "            \"progressive\": false,\n",
       "            \"width\": 0,\n",
       "            \"height\": 0\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_74a9d45dd1c0496592aca31fab97a89e.setOption(option_74a9d45dd1c0496592aca31fab97a89e);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x23132b99eb0>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "db205046",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'Bar' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-11-87890491bd73>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[0my_data1\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdg\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'用户搜索'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_list\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m z=(\n\u001b[1;32m----> 6\u001b[1;33m     \u001b[0mBar\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minit_opts\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mopts\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mInitOpts\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtheme\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mThemeType\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mDARK\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      7\u001b[0m     \u001b[1;33m.\u001b[0m\u001b[0madd_xaxis\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx_data\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      8\u001b[0m     \u001b[1;33m.\u001b[0m\u001b[0madd_yaxis\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"用户搜索\"\u001b[0m \u001b[1;33m,\u001b[0m\u001b[0my_axis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0my_data1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mitemstyle_opts\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mopts\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mItemStyleOpts\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcolor\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"#b51416\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'Bar' is not defined"
     ]
    }
   ],
   "source": [
    "df=pd.read_excel('C:/Users/hcc/Python高级应用/数据表/2011年至今校园霸凌搜索指数数据统计(1).xlsx')\n",
    "dg=df.sort_index(ascending=False)\n",
    "x_data=dg['年份'].to_list() \n",
    "y_data1=dg['用户搜索'].to_list()\n",
    "z=(\n",
    "    Bar(init_opts=opts.InitOpts(theme=ThemeType.DARK))\n",
    "    .add_xaxis(x_data) \n",
    "    .add_yaxis(\"用户搜索\" ,y_axis=y_data1,itemstyle_opts=opts.ItemStyleOpts(color=\"#b51416\"))\n",
    "    .reversal_axis()\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title='2011年至今\"校园霸凌\"搜索指数'),\n",
    "                     xaxis_opts=opts.AxisOpts(name=\"全年搜索指数\"),\n",
    "                     yaxis_opts=opts.AxisOpts(name=\"年份\"),\n",
    "                     datazoom_opts=[opts.DataZoomOpts(orient='vertical')],\n",
    "                     graphic_opts=[\n",
    "                         opts.GraphicImage(\n",
    "                             graphic_item=opts.GraphicItem(\n",
    "                                 id_=\"logo\",right=5,top=5,z=-10,bounding=\"raw\",origin=[75, 75]\n",
    "                             ),\n",
    "                             graphic_imagestyle_opts=opts.GraphicImageStyleOpts(\n",
    "                                 image=image_path,\n",
    "                                 width=150,\n",
    "                                 height=130,\n",
    "                                 opacity=0.4,\n",
    "                             ),\n",
    "                         )\n",
    "                     ],\n",
    "                    )\n",
    ")\n",
    "z.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cdcf0735",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
